<?php
if (!session_start()) session_start();
if (!isset($_SESSION['kiemtradangnhapthinguyet']) || $_SESSION['kiemtradangnhapthinguyet'] != 1) {
    header('location: ../../../index.php');
    die();
}
$table = "sanpham_loai";
if (isset($_POST['ok'])) {
    $bien = $_POST;
    unset($bien['ok']);

    $bien['ngay']  = $ngay;
    $bien['thutu'] = $qt->get_thutu($table);
    //print_r($bien);die;
    $res = $qt->insertObject1($table, $bien);

    if ($res) {
        echo "<script>alert('Thêm dữ liệu thành công !!!');history.go(-1);</script>";
    }
}

?>
<script type="text/javascript">
    function isTest() {
        if (document.getElementById("ten_vi").value == "") {
            alert("You have not entered enough information.");
            return false;
        }
        if (document.getElementById("ten_en").value == "") {
            alert("You have not entered enough information.");
            return false;
        }

        return true;
    }
</script>
<div class="dangnhap_title">
    <a href="index.php" style="color:#F8991D;" title="Trang chủ">Trang chủ</a>
    <span style="font-size:9px;">>></span>
    Sản phẩm
    <span style="font-size:9px;">>></span>
    <a href="index.php?p=<?php echo $table; ?>_quanly" style="color:#F8991D;">Loại sản phẩm</a>
</div>
<form method="post" action="index.php?p=<?php echo $table; ?>_them" onSubmit="return isTest();">
    <div class="dangnhap_col">
        <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
            Vietnamese's Information
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- Tên(*)
        </div>
        <div class="dangnhap_col_input">
            <input type="text" name="ten_vi" id="ten_vi" style="width:520px; padding:0px;"/>
        </div>
    </div>
    <!--
    <div class="dangnhap_col">
        <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
            English's Information
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- Name(*)
        </div>
        <div class="dangnhap_col_input">
            <input type="text" name="ten_en" id="ten_en" style="width:520px; padding:0px;" />
        </div>
    </div>
    -->


    <script>
        function gettheloaitin() {
            var id = document.getElementById("idmenu").value;
            $("#idroot").load("librarys/incs/getloai.php?table=sanpham_root&loai=idmenu&id=" + id);
        }
        function getcl() {
            var id = document.getElementById("idroot").value;
            $("#idcl").load("librarys/incs/getloai.php?table=sanpham_chungloai&loai=idroot&id=" + id);
        }
    </script>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- sản phẩm menu:
        </div>
        <div class="dangnhap_col_input">
            <select name="idmenu" id="idmenu" onchange="gettheloaitin()">
                <option value="0"> - - Chọn - -</option>
                <?php
                $idparent = 0;
                $tinroot  = $qt->get_by_thutu('sanpham_menu');
                while ($row = mysql_fetch_assoc($tinroot)) {
                    if ($idparent == 0) $idparent = $row['id'];
                    ?>
                    <option value="<?php echo $row['id']; ?>"><?php echo $row['ten_vi']; ?></option>
                    <?php
                }
                ?>
            </select>
        </div>
    </div>

    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;-Sản phẩm root:
        </div>
        <div class="dangnhap_col_input">
            <select name="idroot" id="idroot" onchange="getcl()">
                <option value="0"> - - Chọn - -</option>
                <?php
                $idparent   = 0;
                $tintheloai = $qt->get_by_thutu("sanpham_root", -1, -1, "and idmenu = '$idparent'");
                while ($rowtheloai = mysql_fetch_assoc($tintheloai)) {
                    if ($idparent == 0) $idparent = $row['id'];
                    ?>
                    <option value="<?php echo $rowtheloai['id']; ?>"><?php echo $rowtheloai['ten_vi']; ?></option>
                    <?php
                }
                ?>
            </select>
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;-Sản phẩm chủng loại:
        </div>
        <div class="dangnhap_col_input">
            <select name="idcl" id="idcl">
                <option value="0"> - - Chọn - -</option>
                <?php
                $tintheloai = $qt->get_by_thutu("sanpham_chungloai", -1, -1, "and idroot = '$idparent'");
                while ($rowtheloai = mysql_fetch_assoc($tintheloai)) {
                    ?>
                    <option value="<?php echo $rowtheloai['id']; ?>"><?php echo $rowtheloai['ten_vi']; ?></option>
                    <?php
                }
                ?>
            </select>
        </div>
    </div>


    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- Title
        </div>
        <div class="dangnhap_col_input">
            <input type="text" name="title" id="title" style="width:520px; padding:0px;"/>
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- Keyword
        </div>
        <div class="dangnhap_col_input">
            <input type="text" name="keyword" id="keyword" style="width:520px; padding:0px;"/>
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- Description
        </div>
        <div class="dangnhap_col_input">
            <input type="text" name="description" id="description" style="width:520px; padding:0px;"/>
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_title">
            &nbsp; &nbsp; &nbsp;- Hidden or Show:
        </div>
        <div class="dangnhap_col_input">
            <input type="radio" name="anhien" value="1" checked="checked"/>Show
            <input type="radio" name="anhien" value="0"/>Hidden
        </div>
    </div>
    <div class="dangnhap_col">
        <div class="dangnhap_col_input">
            <input type="submit" class="ok" border="0" name="ok" id="ok" value=""/>
            <a href="javascript:history.go(-1);"><img src="imgs/exit_button.png" border="0"/></a>
        </div>
    </div>
</form>